﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLNS.Models
{
    public class PhuCapModels
    {
        private static ITAPMNS2013Entities context = new ITAPMNS2013Entities();
        public static PhuCap GetChiTietDSPhuCap(int id)
        {
            //khoi tao db
            var query = (from s in context.DSPhuCap
                         where s.ID == id
                         select s).FirstOrDefault();
            return query;

        }

        //danh sach PhuCap
        public static List<PhuCap> GetDSPhuCap()
        {
            //khoi tao db
          
            var query = from dt in context.DSPhuCap
                        select dt;
            return query.ToList<PhuCap>();
        }
        public static float GetHeSoPhuCap(int idChucVu)
        {
            //khoi tao db
          
            PhuCap query = (from dt in context.DSPhuCap
                        where dt.ID == idChucVu
                        select dt).First<PhuCap>();
            return (float)query.HeSo;
        }
        //them vao bang dan toc
        public static void Add(PhuCap th)
        {
            
            context.DSPhuCap.AddObject(th);
            context.SaveChanges();
        }
        //Xoa Dan Toc
        public static void Delete(int id)
        {
            
            var query = (from h in context.DSPhuCap
                         where h.ID == id
                         select h).FirstOrDefault();

            context.DSPhuCap.DeleteObject(query);
            context.SaveChanges();

        }
        
        //sua dan toc
        public static void Edit(PhuCap id)
        {
           
            var query = from h in context.DSPhuCap
                        where h.ID == id.ID
                        select h;
            PhuCap kq = query.First<PhuCap>();
            kq = id;
            context.DSPhuCap.ApplyCurrentValues(kq);
            context.SaveChanges();

        }
    }
}